<template>
	<div>
		<p>
			<span style="font-size: 16px;cursor: pointer;float: right;"><Icon type="ios-add-circle" style="font-size: 20px; margin: -3px 5px 0 0;" />新增类目</span></p>
		<br /><br />
		<!-- 案例列表 -->
		<Table border :columns="columns1" :data="caseList"></Table>
		<!-- 分页 -->
		<br /><br />
		<div style="text-align: center;">
			<Page :total="total" show-elevator  @on-change="changePage"/>
		</div>
	</div>
</template>
<script>
	import path from '@/api/path.js';
	let url = path.url;
	import axios from '@/libs/api.request';
	export default {
		name: 'level_1',
		data() {
			return {
				columns1: [
					{   
						title: '编号',
						key: 'id',
						width: 100,
						align: 'center'
					},
					{
						title: '封面',
						key: 'picture',
						width: 150,
						align: 'center',
						columns: {
							'width': '50px'
						},
						render: (h, params) => {
							return h('div', [
								h('img', {
									attrs: {
										src: params.row.picture
									},
									style: {
										width: '40px',
										height: '40px'
									}
								}),
							]);
						}
					},
					{
						title: '类目',
						key: 'name',
						width: 100,
						align: 'center'
					},
					{
						title: '隐患危害',
						key: 'content',
						align: 'center'
					},
					{
						title: '操作',
						key: 'action',
						width: 250,
						align: 'center',
						render: (h, params) => {
							return h('div', [
								h('Button', {
									props: {
										type: 'primary',
										size: 'small'
									},
									style: {
										marginRight: '10px'
									},
									on: {
										click: () => {
											this.goDetail(params.row);
										}
									}
								}, '查看详情'),
								h('Button', {
									props: {
										type: 'error',
										size: 'small'
									},
									on: {
										click: () => {
											this.delect(params.row);
										}
									}
								}, '删除')
							]);
						}
					}
				],
				caseList: [],
				total: 0,
				page: 1
			}
		},
		methods: {
			
			// 获取隐患案例列表
			getCaseList() {
				axios.request({
					url: `${url}CaseArticleCate/getCaseArticleCateList`,
					method: 'post',
					data: {
						page: this.page
						}
				}).then(res => {
					if (res.data.status == 1) {
						this.caseList = res.data.content.data;
						this.total = res.data.content.total;
					} else {
						throw '获取数据失败！'
					}
				})
			},
			// 页面跳转
			changePage(idx){
				this.page = idx;
				this.getCaseList();
			},
			// 删除
			delect(obj){
				axios.request({
					url: `${url}CaseArticleCate/delCaseArticleCate`,
					method: 'post',
					data: {
						id: obj.id
					}
				}).then(res=>{
					if ( res.data.status == 1 ) {
						this.getCaseList();
					} else {
						throw '删除失败！'
					}
				})
			},
			// 查看详情
			goDetail(obj) {
				if (obj) {
					this.$router.push({
						name: 'caseDetails',
						query: {
							id: obj.id
						}
					});
				} else {
					this.$router.push({
						name: '/'
					});
				}
			},
		},
		created() {
			this.getCaseList();
		}
	}
</script>
<style scoped="scoped">
</style>
